 $(function(){
	//授权登陆
	checkoutlogin();
	
	//getuser_info()	
 	
	/*$(document).on('touchend','.more_order_prodcut',function(){//展开或收缩新增汇报
		var $toggle=$(this).prev('.order_prodcut');
		var $_ft=$(this).find('.weui-cell__ft')
		if($_ft.hasClass('show')){	
			$_ft.removeClass("show");
			$toggle.animate({height: 'toggle', opacity: 'toggle'}, "slow");		
			$(this).show();
		}else{
			$_ft.addClass("show")
			$toggle.animate({height: 'toggle', opacity: 'toggle'}, "slow");	
		}

		
	});
	*/
	
	
	$("#workbox").scroll(function () {  // 作品页分页加载	
		var viewH =$(this).height(),//可见高度
          contentH =$(this).get(0).scrollHeight,//内容高度
         scrollTop =$(this).scrollTop();//滚动高度
	   if(scrollTop/(contentH -viewH)>=0.95){  
	   	if(pageEnd){
	   		$('.workbox').append('<div class="weui-loadmore"><i class="weui-loading"></i><span class="weui-loadmore__tips">正在加载</span></div>');				
				getuser_order(10,pageNoSize)
				console.log(pageEnd)
				pageEnd=false;
			}
			
			
	     }
	
	 });
	 
	 $(document).on('click','.open_work',function(e){//查看
		 e.stopPropagation()
		 if($(this).attr("method")==0){
			
			 $("#pic_mask").popup();
			 $(".share_pic_box").find('img').attr('src',$(this).attr("path"));
		 }else if($(this).attr("method")==1){
		 	//$.cookie('order_no', $(this).attr("data-clipboard-text"), { expires: 3600*12, path: '/' }); 
		 	$.cookie('order_no', $(this).attr("data-clipboard-text"), { expires: 3, path: '/' }); 
			 window.location.href=$(this).attr("path");
		 }
	 	
	 })
	 
	

 $(document).on('click','.product_list',function(){//查看
		 
		 if($(this).attr("data-target")){
			 window.location.href=$(this).attr("data-target");
		 }
	 	
	 })
	 
	
})


//获取用户信息
function getuser_info(){
	baseAjax('wechat/userwork/user_info','GET',{user_id:user_id},function(res){
		fans_id=res.data.fans_id;		
		 getuser_order(10,pageNoSize)
	})
	
	
}

//获取用户订单信息
function getuser_order(page_size,page_no){
 	baseAjax('wechat/userwork/order_infor','POST',{fans_id:fans_id,page_size:page_size,page_no:page_no},function(res){	
		user_ordelist (res.data)
		
	})
	
 	
 	
 }
//遍历数据
function user_ordelist (order){
	$(".weui-loadmore").remove();
	if(order.length<=0){
			if(!$("#loadtoast").is(":hidden")){
				$("#loadtoast").hide();
			}
			if(pageNoSize==1){
				$('.workbox').append('<div class="weui-cells__title nodata">暂无订单</div>');
			}else{
			$('.workbox').after('<div class="weui-cells__title">没有更多了</div>');
			}
			pageEnd=false;
	}else{
	
	var Morehtml='<div class="weui-panel__ft">'+
		          '<div class="weui-cell weui-cell_access weui-cell_link more_order_prodcut">'+
		           ' <div class="weui-cell__bd">查看全部2件商品<span class="weui-cell__ft"></span></div>'+		            
		          '</div >'+  
		        '</div>';
	for(var i=0; i<order.length; i++){
		var orderhtml='<div class="weui-panel__hd" tid="'+order[i].tid+'">订单编号： <input  class="tidinput" type="text" value=" '+order[i].tid+'" readOnly>  <a class="copybtn copybtncss" data-clipboard-text="'+order[i].tid+'">复制</a></div>';
		var producthtm='';
		var otherhtml='';
		var firsthtml='';
		var totalnum=order[i].orders.length;
		for(var k=0; k<totalnum; k++){	
			var item=order[i].orders[k];
			var  mothstr=item.method==-1?'':'<a href="javascript:;" class="weui-btn weui-btn_mini weui-btn_primary open_work copybtn"  data-clipboard-text="'+order[i].tid+'" method="'+item.method+'" path="'+item.path+'">制作</a>';
			var itemhtm='<div class="weui-media-box weui-media-box_appmsg product_list" data-target="'+item.target+'">'+
				           '<div class="weui-media-box__hd">'+				              
				            '<img class="weui-media-box__thumb" src="'+item.pic_thumb_path+'">'+
				            '</div>'+
				            '<div class="weui-media-box__bd">'+				              
				              '<p class="weui-media-box__desc">'+item.title+'</p>'+	
				              '<p class="weui-media-box__desc _padding10">'+item.sku_properties_name+'</p>'+	
				            '</div>'+
				            '<div class="weui-cell__ft">'+mothstr+
				            	
				            '</div>'+
				         '</div>';
			/*if(k==0){
				firsthtml=itemhtm;
			}else{*/
				otherhtml=otherhtml+itemhtm;
			//}
		}
		//producthtm=firsthtml+(totalnum>1?'<div class="order_prodcut">'+otherhtml+'</div>':'');		
		
		//$('.workbox').append('<div class="weui-panel weui-panel_access ordernolist">'+orderhtml+'<div class="weui-panel__bd">'+producthtm+'</div>'+(totalnum>1?Morehtml:''));
		$('.workbox').append('<div class="weui-panel weui-panel_access ordernolist">'+orderhtml+'<div class="weui-panel__bd">'+otherhtml+'</div>');
	
	}
	pageNoSize=pageNoSize+1;
	pageEnd=true;
	}
	if($(".workbox").is(":hidden")){
			$(".workbox").show();
	}
	
	if(!$("#loadtoast").is(":hidden")){
			$("#loadtoast").hide();
	}
}
